
//汉诺塔
import java.util.Scanner;

public class morning20231104 {

    private static int count = 0;

    public static void main(String[] args) {
        Scanner sui = new Scanner(System.in);
        while (sui.hasNext()) {
            int n = sui.nextInt();
            Tow(n, 'A', 'B', 'C');
            System.out.println("总共移动了"+count+"次");
        }
    }

    public static void Tow(int n, char str1, char str2, char str3) {
        if (n == 1) {
            move(str1, str3);
        } else {
            Tow(n - 1, str1, str3, str2);//调换3和2的位置，留一个在1上，其他全放在2.
            move(str1, str3);//将1上剩余的移到3上
            Tow(n - 1, str2, str1, str3);//调换1和2的位置，使其全放在3上。
        }
    }

    public static void move(char str1, char str3) {
        System.out.println(str1 + " -> " + str3);
        count++;
    }
}

/*
//递归求斐波那契数列的第 N 项
import java.util.Scanner;

public class morning20231104 {
    public static void main(String[] args) {
        Scanner sui = new Scanner(System.in);
        while (sui.hasNext()) {
            int n = sui.nextInt();
            System.out.println(Repr(n));
        }

    }
    public static int Repr(int n) {
        if (n == 1 || n == 2) {
            return 1;
        } else {
            return Repr(n-1) + Repr(n-2);
        }
    }
}*/



/*
//递归返回的数字之和
import java.util.Scanner;

public class morning20231104 {
    public static void main(String[] args) {
        Scanner sui = new Scanner(System.in);
        while (sui.hasNext()) {
            int n = sui.nextInt();
            System.out.println(Repr(n));
        }

    }
    public static int Repr(int n) {
        if (n < 10) {
            return n;
        } else {
            return (n%10) + Repr(n/10);

        }
    }
}*/


/*
//递归打印数字每一位
import java.util.Scanner;

public class morning20231104 {
    public static void main(String[] args) {
        Scanner sui = new Scanner(System.in);
        while (sui.hasNext()) {
            int n = sui.nextInt();
            Repr(n);
            System.out.println();
        }

    }
    public static void Repr(int n) {
        if (n < 10) {
            System.out.print(n+" ");
        } else {
            Repr(n/10);
            System.out.print((n%10)+" ");
        }
    }
}*/


/*
//递归求和
import java.util.Scanner;

public class morning20231104 {
    public static void main(String[] args) {
        Scanner sui = new Scanner(System.in);
        while (sui.hasNext()) {
            int n = sui.nextInt();
            System.out.println(sum(n));
        }

    }
    public static int sum(int n) {
        if (n == 1) {
            return 1;
        } else {
            return n + sum(n - 1);
        }
    }
}*/

/*
//递归求阶乘
import java.util.Scanner;

public class morning20231104 {
    public static void main(String[] args) {
        Scanner sui = new Scanner(System.in);
        while(sui.hasNext()){
            int n = sui.nextInt();
            System.out.println(factorial(n));
        }

    }
    public  static int factorial(int n){
        if(n == 1){
            return 1;
        } else {
            return n * factorial(n-1);
        }
    }
}*/
